package com.atguigu.gmall.product;

import java.util.concurrent.TimeUnit;

/**
 * @author 李旭
 * @date 2022/1/10 15:05
 * @Description:
 */
public class ThreadDemo {

    public static void main(String[] args) throws Exception{//主线程  张三


        Thread thread = new Thread(() -> { //子线程 李四
            //1000行代码
            //int i = 10 / 0;
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("我是子线程");
        });
        thread.start();

        thread.join();

        Thread thread2 = new Thread(() -> { //子线程 李四
            //1000行代码
            //int i = 10 / 0;
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("我是子线程");
        });
        thread2.start();

        thread2.join();
 /*       new Thread(() -> { //子线程 王五
            //2000行代码

        }).start();*/
        //异步 编排

        System.out.println("主线程的代码");

    }
}
